<?php

require_once('admincontroller.php');

class Tags extends AdminController
{
	function Tags()
	{
		parent::AdminController();
		$this->load->model('Tag');
	}

	function rename_form($id)
	{
		$data['tag'] = $this->Tag->get_by_id($id);
		$this->load->view('admin/tags/_rename_form', $data);
	}
	
	function rename($id)
	{
		$tag = $this->Tag->get_by_id($id);

		$errors = $this->Tag->update($tag, $_POST);
		if (count($errors) == 0 && $this->Tag->save($tag)) {
			return; // OK, status 200
		}
		else {
			$data['error_notice'] = $errors;
			$this->output->set_status_header(400);
			$this->load->view('admin/_partials/notice_message', $data);
		}
	}
	
	function delete($id)
	{
		if (!$this->Tag->delete($id)) {
			$this->output->set_status_header(400);
		}
	}
}	
